﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TimeTracker.Entities;
using TimeTracker.Models;
using TimeTracker.Persistence;
using TimeTracker.Web.Models;

namespace TimeTracker.Web.Controllers
{
    public class HomeController : Controller
    {
        // GET: /Home/
        public ActionResult Index()
        {
            using (var context = new TimeTrackerContext())
            {
                var db = context.Database;

                User user = db.GetUserByEmail("my-user@mailinator.com");

                var query = from e in db.Query<Entry>()
                            where e.UserId == user.Id
                            select e;

                var entries = new List<EntryModel>();
                foreach (var entry in query)
                {
                    var model = EntryModel.FromModel(entry, db.GetClientById(entry.ClientId), db.GetProjectById(entry.ProjectId));

                    entries.Add(model);
                }

                return View(new EntriesReportModel {Entries = entries});
            }
        }
    }
}
